package sort.ui.gwt.client;

import java.util.List;

import sort.result.SortResult;

import com.google.gwt.user.client.ui.FlexTable;

public class ResultTable extends FlexTable {
	int rows = 0;
	
	public ResultTable() {
//		resultTable.setTitle("Results");
//		setText(0, 0, "upper-left corner");
//		setText(2, 2, "bottom-right corner");
//		setWidget(1, 0, new Button("Wide Button"));
		
		setText(0, 0, "No");
		setText(0, 1, "Algorithm");
		setText(0, 2, "Records");
		setText(0, 3, "Exec count");
		setText(0, 4, "Avg time");
		setText(0, 5, "avg mem usage");
		setText(0, 6, "Identity");
		setText(0, 7, "Stability");
		
		getRowFormatter().addStyleName(0, "resultListHeader");
		addStyleName("resultList");
		
	}
	
	public void add(SortResult result) {
		int row = ++rows;
		insertRow(row);
		setText(row, 0, String.valueOf(row));
		setText(row, 1, result.getAlgorithmName());
		setText(row, 2, String.valueOf(result.getRecordCount()));
		setText(row, 3, "1");
		setText(row, 4, String.valueOf(result.getElapsedTime()));
		setText(row, 5, String.valueOf(result.getUsedMemory()));
		setText(row, 6, String.valueOf(result.isSorted()));
		setText(row, 7, String.valueOf(result.isStabled()));
	}
	public void addAll(List<SortResult> results) {
		for (SortResult sortResult : results) {
			add(sortResult);
		}
	}
	public void clear() {
		if ( rows == 0 ) return;
		for ( int i=0; i<rows; i++ ) {
			removeRow(1);
		}
		rows = 0;
	}


}
